<template>
  <div class="content">
    <dt-header :line-number="2" :title="detailsData.allowanceName" :label-width='120' ref='header'>
      <div>
        <div class="btn" v-if="flag=='audit'">
          <Button type="primary" @click="onAudit">审批</Button>
        </div>
        <div class="btn" v-else>
          <Button type="primary" @click='infoOpen'>流程信息</Button>
          <Button type="primary" @click='onExport'>导出</Button>
        </div>
      </div>
    </dt-header>
    
    <dt-grid ref="table" :columns="columns" :list="list" />
    
    <info-modal ref="infoModal"></info-modal>
    <audit-modal ref="audit" />
  </div>
</template>
<script>
  import infoModal from './components/infoModal.vue'
  import auditModal from '@/components/biz/audit/audit-modal.vue'
  import columnOpt from './opt/allowanceSeeColumn'
  import HeaderOpt from './opt/HeaderOpt.js'
  import toolApi from '@/biz/base/tool'
  import incentiveMgr from '@/biz/bonus/incentive'
  import billMgr from '@/biz/bonus/bill'
  
  export default {
    components: {
      infoModal,
      auditModal,
    },
    data() {
      return {
        detailsData: [],
        columns: [],
        list: [],
        flag: this.$route.query.flag,
      }
    },
    mounted() {
      this.columns = columnOpt.options(this)
      this.getDetails()
    },
    methods: {
      infoOpen() {
        let params = {
          businessId: this.$route.query.allowanceId,
          auditType: 5,
        }
        this.$refs.infoModal.create(params)
      },
      onExport() {
        let params = {
          allowanceId: this.$route.query.allowanceId,
        }
        toolApi.downloadCenter(
          '/dt-order/bo/allowance/exportBonusAllowance/[allowanceId]',
          params,
          'get'
        )
      },
      getDetails() {
        let params = {
          allowanceId: this.$route.query.allowanceId,
        }
        incentiveMgr.selectBonusAllowanceInfo(params).then((res) => {
          console.log(res, '项目津贴')
          this.detailsData = res
          this.list = this.detailsData.boAllowanceDetailInfoList
          this.$refs.header.init(new HeaderOpt(this.detailsData), this.detailsData)
        })
      },
      onAudit() {
        billMgr.isCanApproveBonus(this.$route.query.housesId).then(res => {
          this.$refs.audit.show({
            auditId: this.$route.query.auditId,
            businessId: this.$route.query.businessId,
            auditType: 5,
          })
        })
      },
    },
  }
</script>
<style lang="scss" scoped>
  .content {
    padding: 20px;
  }
  
  .btn {
    Button {
      margin-left: 10px;
    }
  }
</style>